﻿using System;
using System.Globalization;
using System.Linq;
using System.Windows.Data;

namespace FFmpegVideoClip.Lib.UtilityControlsTools
{
    public class MediaSameSourceCheck : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null || values.Length < 3 || values.Any(p => p == null))
                return false;

            if (values[2] is not bool IsPlay || !IsPlay)
                return false;
            string? Apath = values.OfType<string>().FirstOrDefault();
            Uri? Bpath= values.OfType<Uri>().FirstOrDefault();
            if (string.IsNullOrWhiteSpace(Apath) || Bpath == null) 
                return false;
            return Apath.Equals(Bpath.LocalPath, StringComparison.OrdinalIgnoreCase);
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException("不支持的操作，该对象仅用于单向绑定");
        }
    }
}
